//
//  GVIndexMessageLeftCell.m
//  GmallVIP
//
//  Created by yemeihua on 15/9/10.
//  Copyright (c) 2015年 yemeihua. All rights reserved.
//

#import "GVIndexMessageLeftCell.h"

@interface GVIndexMessageLeftCell()

@end

@implementation GVIndexMessageLeftCell

+ (NSString *)identifier
{
    static NSString *identifier = @"GVIndexMessageLeftCell";
    return identifier;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        self.messageLabel.textColor = [UIColor yc_colorWithUInt:0x006db8];
        UIImage *image = [UIImage yc_imageWithColor:[UIColor yc_colorWithUInt:0x00b4ff] size:CGSizeMake(ceilf(kScreenWidth * 0.3), 36.0) radius:18.0];
        
        self.messageVoiceView.image = image;
        
//        self.messageVoiceView.playImageView.image = [UIImage imageNamed:@"ReceiverVoiceNodePlaying"];
//        self.messageVoiceView.playImageView.animationImages = @[[UIImage imageNamed:@"ReceiverVoiceNodePlaying001"],
//                                               [UIImage imageNamed:@"ReceiverVoiceNodePlaying002"],
//                                               [UIImage imageNamed:@"ReceiverVoiceNodePlaying003"]];
    }
    return self;
}

- (void)updateConstraints
{
    if(!self.updatedConstraints)
    {
        self.updatedConstraints = YES;
        
        [self.avatorContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo([NSValue valueWithCGSize:CGSizeMake(48.0, 48.0)]);
            make.top.equalTo(@0);
            make.left.equalTo(@18);
        }];
        
        [self.avatorImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo([NSValue valueWithCGSize:CGSizeMake(40.0, 40.0)]);
            make.center.equalTo(self.avatorContainerView);
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.avatorContainerView.mas_bottom).offset(4);
            make.left.equalTo(@0);
            make.right.equalTo(self.mainView.mas_left);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.avatorContainerView.mas_right).offset(18);
            make.top.equalTo(self.avatorContainerView).offset(8);
            make.height.lessThanOrEqualTo(@(self.timeLabel.font.lineHeight));
        }];
        
        [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.avatorContainerView.mas_right).offset(18);
            make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
            make.right.equalTo(self.contentView).offset(-24);
            make.bottom.equalTo(self.contentView);
        }];
        
        [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.lessThanOrEqualTo(self.mainView);
            make.bottom.equalTo(self.contentView);
        }];
        
        ///图片视图
        
        [self.messageImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.equalTo(@170);
            make.height.equalTo(@170);

           // make.bottom.lessThanOrEqualTo(self.mainView);
        }];
        
        ///视频视图
        
        [self.messageVideoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.equalTo(@120);
            make.height.equalTo(self.mainView);
        }];
        
        ///语音视图
        
        [self.messageVoiceView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.equalTo(@(ceilf(kScreenWidth * 0.3)));
            make.height.equalTo(@36.0);
        }];
        
        UIImageView *playImageView = self.messageVoiceView.playImageView;
        
        [playImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.messageVoiceView).offset(16);
            make.centerY.equalTo(self.messageVoiceView);
        }];
        
        [self.messageVoiceView.durationLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.messageVoiceView.mas_right).offset(-8);
            make.centerY.equalTo(self.messageVoiceView);
        }];
        
        ///产品视图
        
        [self.messageProductView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@0);
            make.left.equalTo(@0);
            make.width.equalTo(@([GVMessageProductView width]));
            make.height.equalTo(@([GVMessageProductView width]+126));
        }];
        
        ///活动视图
        
        {
            [self.messagePushView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessagePushView widthForActivity]));
            }];
            
            [self.messagePushView0 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessagePushView widthForActivity]));
            }];
            
            [self.messagePushView1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessagePushView widthForActivity]));
            }];
            
            [self.messagePushView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessagePushView widthForActivity]));
            }];
            
            [self.messagePushView3 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessagePushView widthForActivity]));
            }];
        }
        
        ///注册视图
        
        [self.messageRegisterView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.and.top.and.bottom.equalTo(@0);
        }];
        
        [self.messageRegisterView.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@170);
            make.height.equalTo(@170);
            make.top.equalTo(self.messageRegisterView.titlelabel.mas_bottom).offset(10);
            make.left.equalTo(@0);
        }];
        
        ///订单通知
        
        [self.messageNoticeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.and.top.and.bottom.equalTo(@0);
        }];
        
        ///音乐视图
        
        {
            [self.messageMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.and.bottom.equalTo(@0);
                make.width.equalTo(@([GVMessageMusicView width]));
            }];
        }
        
        [self.gifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.lessThanOrEqualTo(@120);
            make.height.lessThanOrEqualTo(@120);
            make.top.and.left.equalTo(@0);
        }];
    }
    
    [super updateConstraints];
}

@end
